//
//  SelectBaseSheet.swift
//  Exchange
//
//  Created by 孟祥群 on 2018/4/28.
//  Copyright © 2018年 common. All rights reserved.
//

import UIKit

let CoinBtnTag = 500
class SelectBaseSheet: UIView {
    var selectView:UIView = UIView()
    var dataSource:SelectmangerDelegate?
    var backView:UIView?
    
    init(model:SheetModel,coinfig:SelectConfig,titleArr:[String],selectStr:String?,dataSource:SelectmangerDelegate) {
        super.init(frame:CGRect.zero)
//        model.titleArr = titleArr
        self.dataSource = dataSource
        
    }
    
    convenience init(model:SheetModel,coinfig:SelectConfig,dataSource:SelectmangerDelegate) {
        self.init(model: model, coinfig:coinfig, titleArr: [], selectStr: nil, dataSource: dataSource)
        
    }
    
    convenience init(model: SheetModel, coinfig: SelectConfig, selectStr:String? ,dataSource: SelectmangerDelegate) {
        self.init(model: model, coinfig:coinfig, titleArr: [], selectStr: selectStr, dataSource: dataSource)
    }


    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setUpUI() {
        backView = UIView()
        backView?.backgroundColor = UIColor.black.withAlphaComponent(0.3)
        backView?.frame = CGRect(x: 0, y: 0, width: kSCREEN_WIDTH, height: kSCREEN_HEIGHT)
        let tap = UITapGestureRecognizer(target: self, action: #selector(giveUpFirstRespond(sender:)))
        tap.numberOfTapsRequired = 1
        tap.cancelsTouchesInView = false
        backView?.addGestureRecognizer(tap)
        UIApplication.shared.keyWindow?.addSubview(backView!)
        selectView.themeBackground = ThemeManager.ThemeColorKeys.margin
        backView?.addSubview(selectView)
    }
    
    @objc func giveUpFirstRespond(sender:UITapGestureRecognizer) -> Void {
        if (sender.state == UIGestureRecognizerState.ended) {
            let location = sender.location(in: backView)
            if !selectView.point(inside: selectView.convert(location, from: backView), with: nil) {
                SelectActionManger.manager.close()
            }
        }
    }
    
    func showSheet() -> Void {
        selectView.creatBaseAnimation(fromValue: CGPoint(x: selectView.layer.position.x, y: kSCREEN_HEIGHT), toValue: CGPoint(x: selectView.layer.position.x, y: selectView.layer.position.y), duration: 0.1, keyName: "position")
    }
    
    func close() {
       
    }
    @objc func cancelBtnAction() {
        SelectActionManger.manager.close()
    }
    
    deinit {
        
    }
    
}
